package com.eunion.core.exception;

/**
 * 用于验证的异常.
 * 
 * @version 2016年9月2日 下午9:55:38
 */
public class ValidateException extends ProjectException {

	private static final long serialVersionUID = 7425277866194260414L;

	private String msg;

	public ValidateException(String msg) {
		super(msg);
		this.msg = msg;
	}

	public ValidateException(String msg, Throwable throwable) {
		super(msg, throwable);
		this.msg = msg;
	}

	/**
	 * 将CheckedException转换为UncheckedException.
	 */
	public RuntimeException unchecked(Throwable ex) {
		return ExceptionUtil.unchecked(ex);
	}

	/**
	 * 将ErrorStack转化为String.
	 */
	public String getStackTraceAsString(Throwable ex) {
		return ExceptionUtil.getStackTraceAsString(ex);
	}

	/**
	 * 获取组合本异常信息与底层异常信息的异常描述, 适用于本异常为统一包装异常类，底层异常才是根本原因的情况。
	 */
	public String getErrorMessageWithNestedException(Throwable ex) {
		return ExceptionUtil.getErrorMessageWithNestedException(ex);
	}

	/**
	 * 获取异常的Root Cause.
	 */
	public Throwable getRootCause(Throwable ex) {
		return ExceptionUtil.getRootCause(ex);
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	/**
	 * 判断异常是否由某些底层的异常引起.
	 */
	@SuppressWarnings("unchecked")
	public boolean isCausedBy(Exception ex, Class<? extends Exception>... causeExceptionClasses) {
		return ExceptionUtil.isCausedBy(ex, causeExceptionClasses);
	}
}
